home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
tlx_sq21.zip
/
GLOBAL.SLT
< prev
next >
Wrap
Text File
|
1992-03-20
|
9KB
|
256 lines
//-----------------------------------------------------------
// GLOBAL.SL? Save global variables in Telix.
//
// Calling sequence:
// Read the variable "NAME", result in <variable string>:
// call ("GLOBAL","R","NAME",<variable string>);
// If "NAME" is not found, an empty string is returned.
// Write the string <variable string> into "NAME":
// call ("GLOBAL","W","NAME",<variable string>);
// If "NAME" can not be stored (not enough room) the variable
// will not be stored, and the script will return the code -1.
// Delete a variable:
// call ("GLOBAL","W","NAME",0); // (the "0" must be included)
// or call ("GLOBAL","D","NAME",0); // (the "0" may be omitted)
// In variable names, case is insignificant. The variables may be
// *any* string, except the length is limited to 80 characters
// The script can store up to 40 variables of length <=20 characters,
// and 10 variables of 20 < length <=80 characters,
// Make sure that the longest length you'll ever use is specified
// the first time you define a variable. Otherwise, if you want to
// modify a <20 char. variable to >20 characters, you must delete
// the original first.
//-----------------------------------------------------------
// If you have suggestions for improving this script, please suggest
// improvements to me via old-fashioned snail-mail to:
// Author: Inge Vabekk
// Hamangskogen 108
// N-1300 SANDVIKA
// NORWAY
// tel. (472) 546 396
str shortnames[360] // Table of names for 60 short strings of 6.
,longnames [60] // Table of names for 10 long strings of 6.
,shortstrings [1260] // 60 strings of length 21
,longstrings [810] // 10 strings of length 81
,helpname [6] // Temporary for name
,spaces[6]= " " // Store spaces.
,helpvar [81] // Temporary for string
; // with (room for terminating zero)
int next_short_entry=0
,next_long_entry=0
,namelen // Length of names
,longstringlen=81 // Length of strings.
,shortstringlen=21
,varlen // Length of current string.
,long // Long/short indocator
,get = 0 // Code to GET a variable.
,put = 1 // Code to PUT a variable.
;
//-----------------------------------------------------------
// Script starts here.
//-----------------------------------------------------------
main (str rwrite, str name, str varname)
{
int i, j, l1, l2;
namelen = strmaxlen(helpname);
varlen = strlen(varname);
if (rwrite=="R")
i = read (name,varname); // Read the value.
else if (rwrite=="W")
{ if (strlen(varname) > 0)
i = write (name,varname); // write this name.
else
i = write (name,""); // Delete.
if (i < 0)
{ helpvar = "T²: Global script has no room for variable ";
strcat (helpvar,name);
strcat (helpvar," = ");
strcat (helpvar,varname);
l1 = 40-strlen(helpvar)/2 - 1;
l2 = l1+strlen(helpvar);
clear_scr();
box (l1-6,7,l2+5,16,176,1,15);
box (l1-4,8,l2+3,15,177,1,15);
box (l1-2,9,l2+1,14,178,1,15);
pstraxy (helpvar,l1,11,79);
pstraxy ("Please report to author!",28,12,79);
tone (100,200);
gotoxy (0,24);
}
}
else if (rwrite=="D")
i = write (name,"");
else if (rwrite=="L") // List all names.
{ prints ("ALL SHORT GLOBAL VARIABLES:");
for (i=j=0; i<next_short_entry; i=i+namelen)
{ substr (shortstrings,j,shortstringlen,helpvar);
substr (shortnames,i,namelen,helpname);
printsc(helpname);
printsc (":");
prints (helpvar);
j = j+shortstringlen;
}
prints ("ALL LONG GLOBAL VARIABLES:");
for (i=j=0; i<next_long_entry; i=i+namelen)
{ substr (longstrings,j,longstringlen,helpvar);
substr (longnames,i,namelen,helpname);
printsc(helpname);
printsc (":");
prints (helpvar);
j = j+longstringlen;
}
}
return (i); // Return with code.
}
//-----------------------------------------------------------
// Read a variable.
//-----------------------------------------------------------
read (str name, str varname)
{
move (name); // Move name to global
return (getput (0,varname)); // and read.
}
//-----------------------------------------------------------
// Write a variable.
//-----------------------------------------------------------
write(str name, str varname)
{
move (name); // Move name to global
return (getput (1,varname)); // and write.
}
//-----------------------------------------------------------
// Move name to global area.
//-----------------------------------------------------------
move(str name)
{
helpname = name; // Move name to global.
strupper(helpname); // Make upper characters
strcat (helpname,spaces); // fill with spaces
}
//-----------------------------------------------------------
// Read or write a name to or from the storage area.
//-----------------------------------------------------------
getput (int write, str varname)
{
int c, i, j, exist;
exist = strpos (longnames,helpname,0); // Check if name is in table.
if (exist >= 0)
long = 1;
else
{ long = 0;
exist = strpos (shortnames,helpname,0); // Check if name is in table.
}
if (exist < 0) // Non-existent?
{ if (!write) // Read?
{ varname = ""; // Yes. Nothing there.
return(-1);
}
long = varlen > 20;
if (long) // Add long variable
{ exist = strpos (longnames,spaces,0);// Deleted variable found?
if (exist >= 0) // Must be at correct position!
exist = ((exist+namelen-1)/namelen)*namelen;
else // No, expand table.
{ if (next_long_entry >= strmaxlen(longnames))
{ status_wind ("T²: Overflow in long name table!",30);
return (-1);
}
exist = next_long_entry;
next_long_entry = next_long_entry + namelen;
//!!!!!!!!!!!!!!!!!!!!!!!!
// printsc ("Long: ");
// printn (Next_long_entry);
// prints ("");
}
// Move all characters.
copychrs (helpname,longnames,exist,namelen);
}
else // Add short variable
{ exist = strpos (shortnames,spaces,0);// Deleted variable found?
if (exist >= 0) // Must be at correct position!
exist = ((exist+namelen-1)/namelen)*namelen;
else // No, expand table.
{ if (next_short_entry >= strmaxlen(shortnames))
{ status_wind ("T²: Overflow in short name table!",30);
return (-1);
}
exist = next_short_entry;
next_short_entry = next_short_entry + namelen;
}
// Move all characters.
copychrs (helpname,shortnames,exist,namelen);
}
}
// "exist" contains start subscript for the variable name.
// "j" contains start subscript for its contents.
// "long"=1; Variable is in "longstrings
// "long"=0; Variable is in "shortstrings
if (long)
{ j = (exist/namelen)*longstringlen; // Find start position.
if (write) // Write?
{ if (strlen(varname)==0) // Yes. Delete?
copychrs (spaces // Write over with spaces.
,longnames,exist,namelen);
else
copystr (varname // Copy name.
,longstrings,j,longstringlen-1);
}
else // Read:
substr (longstrings // Copy variable.
,